//
//  IRCaptionView.m
//

#import "IRCaptionView.h"

#import "IRController.h"

@implementation IRCaptionView

//--------------------------------------------------------------------------------------------------
- (void) dealloc
{
	[caption release];

	[super dealloc];
}

//--------------------------------------------------------------------------------------------------
- (void) setCaption:(NSString*) newCaption
{
	[caption release];
	caption = newCaption;
	[caption retain];
	[self setNeedsDisplay: YES];
}

//--------------------------------------------------------------------------------------------------
- (void) drawRect:(NSRect) rect
{
	CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

	NSSize size = [self bounds].size;
	int separator = [[IRController sharedController] separator];

	if (nil != caption)
	{
//		int lineHeight = [[IRController sharedController] lineHeight];
		NSDictionary *attrs = [[IRController sharedController] menuAttributes];
		NSSize sizeCaption = [caption sizeWithAttributes: attrs];

		int captionAreaHeight = size.height - separator;
		[caption drawAtPoint: 
			NSMakePoint(
				(size.width - sizeCaption.width) / 2, 
				size.height - ((captionAreaHeight + sizeCaption.height) / 2))
			withAttributes: attrs];
	}

	[[NSColor whiteColor] set];
	CGContextFillRect(context, CGRectMake(0, separator, size.width, 5));
}

@end
